<?php
class SiteController extends Zend_Controller_Action{
	public function init(){
		$this->view->baseUrl = $this->_request->getBaseUrl();
		Zend_Loader::loadClass('plmorder');
		Zend_Loader::loadClass('product');
		}
		
	function indexAction()	
    { 	
		
		//$products=$plm->getAllProduct();
		/*$file=$this->_request->getBaseUrl().'/public/data/temp.data';
		file_put_contents($file,serialize($products));*/
		//echo "<br />产品数:".sizeof($products);
		//print_r($products[0]);
		//echo $id=$products[0]['product_id'];
		//$product=$plm->getOneProduct($id);
		//foreach($product as $key=>$value){
			//echo $key."<br />";
			//}
		//print_r($product);
		$this->view->title = 'plima管理系统';
		$this->render();
    } 
	
	function orderAction(){
		$id=$this->_request->getParam('id');
		if(isset($id)){
		$this->view->id=$id;
		$this->view->title = 'plima管理系统';
		$this->render();
		//$config=Zend_Registry::get('config');
//		$url=$config->$id->url;
//		$username=$config->$id->username;
//		$password=$config->$id->password;
//		$plm=new plmorder($url,$username,$password);
//		$orders=$plm->getAllOrder();		
//		echo "1";
		}
		else{
			$this->view->id=$id;
			$this->view->title = 'plima管理系统';
			$this->render();
			}
	}
			
	function productAction(){
			$id=$this->_request->getParam('id');
			$config=Zend_Registry::get('config');
			$url=$config->$id->url;		
			$this->view->id=$id;
			$this->view->website='http://'.$url;
			$this->view->title = 'plima管理系统';
			$this->render();
		}		
	
	function productdataAction(){
			$id=$this->_request->getParam('id');
			$start=$this->_request->getParam('start')?$this->_request->getParam('start'):"0";
			$limit=$this->_request->getParam('limit')?$this->_request->getParam('limit'):"10";
			$product=new product($id);
			$products=$product->getAll();
			$total=sizeof($products);
			$products=array_slice($products,$start,$limit);
			$this->view->total=$total;
			$this->view->json=json_encode($products);
		}
	
	function orderdataAction(){
		$id=$this->_request->getParam('id');
		$start=$this->_request->getParam('start')?$this->_request->getParam('start'):"0";
		$limit=$this->_request->getParam('limit')?$this->_request->getParam('limit'):"10";
		$product=new product($id);
		$orders=$product->getAllOrder($start,$limit);		
		echo $orders;
		exit;
		//$this->view->total=sizeof($orders);
		//$this->view->json=json_encode($orders);				
		}
	
	function testAction(){
		$id=$this->_request->getParam('id');
		$product=new product($id);
		$orders=$product->getAllOrder();
		print_r($orders);
		exit;
		}
	
		
}
?>